<%@ page import="cardbs.domain.Department" %>
<%@ page import="cardbs.domain.Employee" %>
<%@ page import="cardbs.domain.Work" %>
<%@ page import="cardbs.domain.Part" %>
<%@ page import="cardbs.domain.Vehicle" %>
<%@ page import="cardbs.domain.Deptype" %>
<%@ page import="cardbs.domain.Customer" %>
<%@ page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Έναρξη Service</title>
<script type="text/javascript">
<!--

function validate_form ( )
{
    valid = true;
	if (document.enarksiService.trafficNo.value =="")
    {
        alert ("Παρακαλώ δώστε τον αριθμό κυκλοφορίας του οχήματος για SERVICE" );
        valid = false;
    }	
    return valid;
}

//-->
</script>
</head>
<body>
<% 
Employee employee = (Employee)session.getAttribute("DepartmentUser");
//HashSet <Work> works = (HashSet)session.getAttribute("allWorks");
String[] parts = (String[])session.getAttribute("allPartsName");
String[] company = (String[])session.getAttribute("allPartsCompany");
Double[] price = (Double[])session.getAttribute("allPartsPrice");
String[] works = (String[])session.getAttribute("allWorks");
Integer[] workCode = (Integer[]) session.getAttribute("allWorksCode");
Double[] workPrice = (Double[])session.getAttribute("allWorksPrice");
Integer[] partsAmount = (Integer[]) session.getAttribute("allAmount");
Vehicle vehicle = (Vehicle)session.getAttribute("vehicle");
//Customer customer = (Customer)session.getAttribute("customer");
%>
 <FORM Name = "enarksiService" action="/car-dbs-implementation/KatagrafiServlet" onsubmit="return validate_form()" method="post">
 <div align="center">
<jsp:include page="exitPage.jsp"/>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
					<td width="32%"><img
						src="../../images/loginPages/ΕνημέρωσηΟχήματος.png" alt="Service A.E."
						width="260" height="228" /></td>
					<td style="width: 206px" width="842">
<h2>Εισάγετε τον αριθμό κυκλοφορίας του αυτοκινήτου που θέλετε να ξεκινήσετε - ενημερώσετε SERVICE</h2>
 
  </td>
  </tr>
  </table>
  <table width="40%">
  <tr>
    <td width="12%">
    <td>Αριθμός κυκλοφορίας </td>
    <td><input type="text" name="trafficNo"></td>
  </tr>
       <%
		String errorVehicleNotExists = (String)session.getAttribute("errorVehicleNotExists");
		
		if ((errorVehicleNotExists!=null) && (errorVehicleNotExists.equals("true")))
		{
		%>
		<tr>
    		<td></td>
    		<td><font size="4" face="arial" color="red">To όχημα δεν υπάρχει!!! Παρακαλώ ελέγχξε ότι δώσατε το σωστό αριθμό κυκλοφορίας.</font></td>
  		</tr><%
  		session.setAttribute("errorVehicleNotExists","false");
		}%>		
	
  <tr>
    <td>&nbsp;</td>
  </table>
  <table>
  <tr>
  <td width="12%">
  <td widht="5%" width="56">
					<input TYPE="submit" VALUE="Εύρεση-Έναρξη Service" style="width: 193px">
					</td>
					<td widht="5%" width="56">
					<a href="/car-dbs-implementation/uipages/firstPagePages/DepartmentUserViewLoginPage.jsp"><img src="../../images/CancelButton.png" style="border:1px solid black;"/></a>
	</td>
</tr>
</table>
</div>
</FORM>
<FORM Name = "kartelaService" action="/car-dbs-implementation/SaveServiceInfoServlet" method="post">
<% if(vehicle != null){ 
session.setAttribute("vehicle", vehicle);
%>
<table style="border:1px solid;">
<tr><td colspan="8" style="border:1px solid; font-size:18pt; font-weight:bold;" align="center">ΚΑΡΤΕΛΑ SERVICE AYTOKINHTOY</td></tr>
<tr><td colspan="8" style="border:1px solid; font-size:14pt; font-weight:bold;" align="center">Στοιχεία Αυτοκινήτου</td></tr>
<tr>
<td style="border:1px solid;">ΑΡ.ΚΥΚΛΟΦΟΡΙΑΣ:</td><td style="border:1px solid;"><%=vehicle.getTrafficNo()%></td>
<td style="border:1px solid;">Κατασκευαστής:</td><td style="border:1px solid;"><%=vehicle.getBrand()%></td>
<td style="border:1px solid;">Μοντέλο:</td><td style="border:1px solid;"><%=vehicle.getModel()%></td>
<td style="border:1px solid;">Χρώμα:</td><td style="border:1px solid;"><%=vehicle.getColour()%></td>
</tr>
<tr><td colspan="8" style="border:1px solid; font-size:14pt; font-weight:bold;" align="center">Επιλογή εργασιών SERVICE</td></tr>
<% if(works != null) {
int worksNumber = (Integer) session.getAttribute("worksNumber");
int w=0;
try {
for (w=0; w<worksNumber;w++){
%>
<tr><td colspan="2"><%= workCode[w]%></td><td colspan="2"><%= works[w]%></td><td colspan="2"><%= workPrice[w]%></td><td colspan="2"><input type="radio" name="selectone<%=w%>" /></td></tr>
<input type="hidden" name="workCode<%=w %>" value="<%= workCode[w]%>" />
<input type="hidden" name="workDescription<%=w %>" value="<%= works[w]%>" />
<input type="hidden" name="workPrice<%=w %>" value="<%= workPrice[w]%>" />
<%
}
session.setAttribute("synoloWorks",w);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
%>
<input type="hidden" name="synoloWorks" value="<%=w%>" />
<%	
}
%>
<tr><td colspan="8" style="border:1px solid; font-size:14pt; font-weight:bold;" align="center">Επιλογή ανταλλακτικών SERVICE</td></tr>
<% if(parts != null) {
int partsNumber = (Integer) session.getAttribute("partsNumber");
int j=0;
try {
for (j=0; j<partsNumber;j++){
%>
<tr><td colspan="2"><%= parts[j]%></td><td colspan="2"><%= company[j]%></td><td><%= price[j]%></td><td><%= partsAmount[j]%></td><td><input type="text" name="amount<%=j%>" size="3" /></<td><input type="radio" name="selecttwo<%=j%>" /></td></tr>
<input type="hidden" name="oldamount<%=j %>" value="<%= partsAmount[j]%>" />
<%
}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		//e.printStackTrace();
		%>
		<font size="4" face="arial" color="red">Δεν υπάρχουν ανταλλακτικά</font>
	<%
	}
	%>
	<input type="hidden" name="synolo" value="<%=partsNumber%>" />
	<%
}
%>
</table>
  <table>
  <tr>
  <td width="12%">
  <td widht="5%" width="56">
					<input TYPE="submit" VALUE="Εισαγωγή" style="width: 193px">
					</td>
					<td widht="5%" width="56">
					<a href="/car-dbs-implementation/uipages/firstPagePages/DepartmentUserViewLoginPage.jsp"><img src="../../images/CancelButton.png" style="border:1px solid black;"/></a>
	</td>
</tr>
</table>
</form>
<% } //if vehicle %>
 <%
		String serviceCreated = (String)session.getAttribute("serviceCreated");
		
		if ((serviceCreated!=null) && (serviceCreated.equals("true")))
		{
		%>
		<tr>
    		<td></td>
    		<td><font size="4" face="arial" color="green">Το service δημιουργηθηκε.<%= request.getParameter("nofdwrks") %></font></td>
  		</tr><%
  		session.setAttribute("errorVehicleNotExists","false");
		}%>	
		<%
		String serviceExist = (String)session.getAttribute("serviceExist");
		
		if ((serviceExist!=null) && (serviceExist.equals("true")))
		{
		%>
		<tr>
    		<td></td>
    		<td><font size="4" face="arial" color="red">υπαρχει<%= request.getParameter("nofdwrks") %></font></td>
  		</tr><%
  		session.setAttribute("errorVehicleNotExists","false");
		}%>			
</body>
</html>